package com.easondongh.blog.advice;

import com.easondongh.blog.exception.BlogException;
import com.easondongh.blog.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 统一异常处理
 * @author EasonDongH
 * @date 2020/3/19 10:31
 */
@Slf4j
@ControllerAdvice
public class BlogExceptionAdvice {

    @ExceptionHandler(BlogException.class)
    @ResponseBody
    public Result<Object> exceptionHandler(BlogException exception) {
        log.error("[统一异常处理] ", exception);
        return new Result<>(exception.getResultEnum().getCode(), exception.getResultEnum().getMsg());
    }
}
